package com.vancouver.knows.business.tracker;

import java.util.List;
import java.util.Map;

import com.pangu.bean.PageableResult;
import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.pangu.task.mark.ATaskMark;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.CityNewsInfo;
import com.vancouver.knows.business.cache.CityNewsInfoCache;
import com.vancouver.knows.business.service.impl.FetchCityNewsHandler;
import com.vancouver.knows.business.task.mark.FetchCityNewsTaskMark;

/**
 * 获取城事列表
 * 
 * @author chenxunlin01
 * 
 */
public class FetchCityNewsTracker extends ABInvokeTracker {

	public FetchCityNewsTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	protected void handleTaskRefresh(ATaskMark taskMark, OperateResult result) {
		CityNewsInfoCache cityNewsInfoCache = module.getCacheManager().getCityNewsInfoCache();
		cityNewsInfoCache.deleteItemInfoIndexFromCache(taskMark);
	}

	@Override
	public String TAG() {
		return FetchCityNewsTracker.class.getSimpleName();
	}

	@Override
	public void handleResult(OperateResult result) {
		PageableResult pageableResult = (PageableResult) result.getResultData();
		if (pageableResult.getContent() != null) {
			Map<String, Object> map = (Map<String, Object>) pageableResult.getContent();
			List<CityNewsInfo> cityNewsInfoList = (List<CityNewsInfo>) map.get(FetchCityNewsHandler.KEY_POSTS);
			FetchCityNewsTaskMark fetchCityNewsTaskMark = (FetchCityNewsTaskMark) result.getTaskMark();
			fetchCityNewsTaskMark.setPageInfo(pageableResult.getPageInfo());
			module.getCacheManager().getCityNewsInfoCache().addItemInfoToCache(fetchCityNewsTaskMark, cityNewsInfoList);

		}
	}
}
